package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.LibraryCardDao;
import com.ocean.entity.library.LibraryCard;
import com.ocean.service.library.LibraryCardService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class LibraryCardServiceImpl implements LibraryCardService {
    @Autowired
    private LibraryCardDao libraryCardDao;

    @Override
    public R save(LibraryCard libraryCard) {
        if (libraryCardDao.insert(libraryCard) > 0) {
            return R.ok();
        } else {
            return R.fail("新增借阅卡失败");
        }
    }

    @Override
    public R del(int id) {
        if (libraryCardDao.delete(id)>0) {
            return R.ok();
        }else {
            return R.fail("删除借阅卡失败");
        }
    }

    @Override
    public R update(LibraryCard libraryCard) {
        if (libraryCardDao.update(libraryCard)>0) {
            return R.ok();
        }else {
            return R.fail("更新借阅卡失败");
        }
    }

    @Override
    public R queryPage(int page, int size) {
        PageHelper.startPage(page, size);
        PageInfo<LibraryCard> pageInfo = new PageInfo<>(libraryCardDao.selectAll());
        return R.ok(pageInfo);
    }

    @Override
    public R selectIdByName(String name) {
        return R.ok(libraryCardDao.selectIDByName(name));
    }
}
